package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.Customer;
import cn.wolfcode.car.business.domain.StockBill;
import cn.wolfcode.car.business.domain.Store;
import cn.wolfcode.car.business.query.StockBillQuery;
import cn.wolfcode.car.business.service.ICustomerService;
import cn.wolfcode.car.business.service.IStockBillService;
import cn.wolfcode.car.business.service.IStoreService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 岗位控制器
 */
@Controller
@RequestMapping("business/stockBill")
public class StockBillController {
    //模板前缀
    private static final String prefix = "business/stockBill/";

    @Autowired
    private IStockBillService stockBillService;

    @Autowired
    private IStoreService storeService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:stockBill:view")
    @RequestMapping("/listPage")
    public String listPage(Model model){
        List<Store> storeList = storeService.list();
        model.addAttribute("storeList",storeList);
        return prefix + "list";
    }

    // 跳转到添加出入库操作  type为判断为入库还是出库
    @RequiresPermissions("business:stockBill:newBill")
    @RequestMapping("/newBill")
    public String billItems(Integer type,Model model){
        List<Store> storeList = storeService.list();
        model.addAttribute("storeList",storeList);
        model.addAttribute("type",type);
        return prefix + "newBill";
    }


    @RequestMapping("/checkBill")
    @ResponseBody
    public AjaxResult checkBill(Long id){
        stockBillService.checkBill(id);
        return AjaxResult.success();
    }
    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:stockBill:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StockBill> query(StockBillQuery qo){
        return stockBillService.query(qo);
    }

    //新增
    @RequiresPermissions("business:stockBill:add")
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockBill stockBill){
        stockBillService.save(stockBill);
        return AjaxResult.success();
    }

    //编辑
    @RequiresPermissions("business:stockBill:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(StockBill stockBill){
        stockBillService.update(stockBill);
        return AjaxResult.success();
    }

    //作废
    @RequiresPermissions("business:stockBill:cancelBill")
    @RequestMapping("/cancelBill")
    @ResponseBody
    public AjaxResult cancelBill(Long id){
        stockBillService.cancelBill(id);
        return AjaxResult.success();
    }



}
